
package cookbook;

import java.util.Stack;
import java.util.StringTokenizer;

/**
 * 讓一個字串, 這個字字串是由很多英文單所組成, 如 "This is a book", 如何轉成 "book a is This", 採用<br>
 * Stack 先進後出的做法<br>
 * <br>
 * Copyright: Copyright (c) 2001-2007<br>
 * Company: 一零四資訊科技股份有限公司
 * 
 * @author Eric.Kao(eric.kao@104.com.tw)
 * @version 1.0
 */
public class StringReverse
{
	public StringReverse()
	{
		String str = "This is a book";

		StringTokenizer token = new StringTokenizer( str );
		
		Stack stack = new Stack();

		while( token.hasMoreTokens() )
		{
			String word = token.nextToken();

			stack.push( word );
		}

		System.out.println( str + "(Reverse):" );
		while( !stack.empty() )
		{
			System.out.print( ( String )stack.pop() + ", " );
		}
	}

	public static void main( String[] args )
	{
		new StringReverse();
	}
}
